<!DOCTYPE html>
<html>
<head>
    <title>我的游记</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/userTravels.css"/>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>

    <script>
        $(function () {

            //拿到当前用户
            var user = JSON.parse(sessionStorage.getItem("user"));
            //console.log(user);

            //当前页的input框
            var currentInput = $('#currentPage');

            //用于存储游记的数组容器
            var travelArr = [];

            //总页数
            var pages = 1;

            //获取我的游记数据
            function query() {

                //获取当前页的值
                var currentPage = currentInput.val();//1

                $.get('/users/' + user.id + '/travels', {currentPage: currentPage}, function (data) {

                    //合并两个数组
                    $.merge(travelArr, data.list);

                    var json = {list: travelArr}//将数组封装成一个json对象,属性名为loop渲染指定的list
                    //重新渲染数据
                    $('.travels').renderValues(json, {
                        'getAddress': function (item, value) {
                            var add = $(item).data('href');
                            $(item).attr('href', add + value);
                        }
                    });

                    /*//将返回的数据渲染
                    $('.travels').renderValues(data);*/


                    //从pageInfo中获取总页数,并设置
                    pages = data.pages;
                });

                //当前页input框+1维护,不能用函数内的变量
                currentInput.val(parseInt(currentPage) + 1);//字符串记得转成数字
            }

            //默认查询第一页的数据
            query();

            //当页面滚动条变化时,执行的函数
            $(window).scroll(function () {
                if ($(document).scrollTop() + $(window).height() >= $(document).height()) {
                    //获取当前页
                    var currentPage = currentInput.val();
                    //判断是否大于最后一页
                    if (currentPage <= pages) {
                        query();
                    } else {//最后一页,提示
                        $(document).dialog({
                            type: 'notice',
                            infoText: '到底',
                            autoClose: 1500,
                            position: 'center'  // center: 居中; bottom: 底部
                        });
                    }
                }
            });

        });
    </script>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="profiles.html">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
            <span>我的游记</span>
        </div>
        <div class="col"></div>
    </div>
</div>

<input type="hidden" name="currentPage" id="currentPage" value="1"/>

<div class="container travels">
    <dl class="list" render-loop="list">
        <dd>
            <!--<a data-href="editTravels.html?id=" render-attr="data-id=list.id" onclick="">-->
            <!--利用jrender插件自定义属性,属性值可以从数据中获取出来-->
            <a data-href="editTravels.html?id=" render-fun="getAddress" render-key="list.id">
                <img render-src="list.coverUrl">
                <h6 class="title" render-html="list.title"></h6>
                <p>最近更新时间 <span render-html="list.lastUpdateTime"></span>
                    <span class="span-right">
								  <i class="fa fa-heart"></i><span render-html="list.collectCount"></span>收藏
							  <i class="fa fa-thumbs-o-up" id="likeBtn"></i><span render-html="list.likeCount"></span>点赞</span>
                </p>
            </a>
        </dd>
    </dl>
</div>

<script>

</script>
</body>
</html>
